package com.cskaoyan.service.admin;

import com.cskaoyan.bean.vo.admin.stat.*;
import com.cskaoyan.mapper.MarketUserMapper;
import com.cskaoyan.mapper.StateMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * /**
 *
 * @author 徐宇航
 * @since 2022/11/20 23:49
 */
@Service
public class StatServiceImpl implements StatService{
    @Autowired
    MarketUserMapper userMapper;
    @Autowired
    StateMapper stateMapper;

    @Override
    public OrdersVo stateOrder() {
        List<OrdersInADay>ordersInADays=stateMapper.stateOrder();
        ArrayList<OrdersSingleVo> ordersSingleVos = new ArrayList<>();
        for (OrdersInADay ordersInADay : ordersInADays) {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            String timeStr = format.format(ordersInADay.getDay());
            OrdersSingleVo ordersSingleVo = new OrdersSingleVo();
            ordersSingleVo.setAmount(ordersInADay.getAmount());
            ordersSingleVo.setOrders(ordersInADay.getOrders());
            ordersSingleVo.setDay(timeStr);
            ordersSingleVo.setCustomers(ordersInADay.getCustomers());
            ordersSingleVo.setPcr(ordersInADay.getPcr());
            ordersSingleVos.add(ordersSingleVo);
        }
        OrdersVo ordersVo = new OrdersVo();
        ordersVo.setRows(ordersSingleVos);
        return ordersVo;
    }

    @Override
    public GoodsStatsVo stateGoods() {
       List<GoodsRowsEntity> goodsRowsEntities=stateMapper.stateGoods();
        ArrayList<GoodsSingleVo> goodsSingleVos = new ArrayList<>();
        for (GoodsRowsEntity goodsRowsEntity : goodsRowsEntities) {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            String timeStr = format.format(goodsRowsEntity.getDay());
            GoodsSingleVo goodsSingleVo = new GoodsSingleVo();
            goodsSingleVo.setDay(timeStr);
            goodsSingleVo.setOrders(goodsRowsEntity.getOrders());
            goodsSingleVo.setAmount(goodsRowsEntity.getAmount());
            goodsSingleVo.setProducts(goodsRowsEntity.getProducts());
            goodsSingleVos.add(goodsSingleVo);
        }
        GoodsStatsVo goodsStatsVo = new GoodsStatsVo();
        goodsStatsVo.setRows(goodsSingleVos);
        return goodsStatsVo;
    }

    @Override
    public List<Map> stateUsers() {
        return stateMapper.queryStatUser();
    }
}
